-- CALC_CAVE_BONUS_13

-- 计算怪物巢穴副本奖励
-- @param user    玩家对象
-- @param args    奖励计算参数
-- @param grade   副本难度
-- @param layer   地牢层数
return function(user, args, grade, layer)
    -- caution：如果修改该公式，服务器请一并修改

    -- grade : 副本难度
    -- layer : 地牢层数
    local maxHp = 0;
    local randSeed  = DungeonM.getRandSeed("DUNGEON_CAVE13");
    local randSeed2 = DungeonM.getRandSeed("DUNGEON_CAVE13");
    local arr, arr2 = {}, {};

    if grade == INSTANCE_GRADE_HARD then
        maxHp = 20;
        arr2   = { { ["class_id"] = 1102, ["amount"] = math.max(1, math.modf(layer / 20)), ["ratio"] = 100 },       -- 魔铁+floor/20
                   { ["class_id"] = 1104, ["amount"] = math.max(1, math.modf(layer / 20)), ["ratio"] = 100 },       -- 暗钢+floor/20
                   { ["class_id"] = 1106, ["amount"] = math.max(1, math.modf(layer / 20)), ["ratio"] = 100 },       -- 秘银+floor/20
                   { ["class_id"] = 1108, ["amount"] = math.max(1, math.modf(layer / 20)), ["ratio"] = 100 }, };    -- 恒金+floor/20
        arr    = { { ["class_id"] = 5041, ["amount"] = 1, ["ratio"] = 100, },                                       -- 宝物“龙鳞盔”×1
                   { ["class_id"] = 5042, ["amount"] = 1, ["ratio"] = 100, },                                       -- 宝物“龙鳞甲”×1
                   { ["class_id"] = 5043, ["amount"] = 1, ["ratio"] = 100, },                                       -- 宝物“龙鳞护腕”×1
                   { ["class_id"] = 5044, ["amount"] = 1, ["ratio"] = 100, }, };                                    -- 宝物“龙鳞腰带”×1
    elseif grade == INSTANCE_GRADE_DIFFICULT then
        maxHp = 10;
        arr2   = { { ["class_id"] = 1102, ["amount"] = math.max(1, math.modf(layer / 20)), ["ratio"] = 100 },       -- 魔铁+floor/20
                   { ["class_id"] = 1104, ["amount"] = math.max(1, math.modf(layer / 20)), ["ratio"] = 100 },       -- 暗钢+floor/20
                   { ["class_id"] = 1106, ["amount"] = math.max(1, math.modf(layer / 20)), ["ratio"] = 100 }, };    -- 秘银+floor/20
        arr    = { { ["class_id"] = 5031, ["amount"] = 1, ["ratio"] = 100, },                                       -- 宝物“秩序头盔”×1
                   { ["class_id"] = 5032, ["amount"] = 1, ["ratio"] = 100, },                                       -- 宝物“秩序铠甲”×1
                   { ["class_id"] = 5033, ["amount"] = 1, ["ratio"] = 100, },                                       -- 宝物“秩序护腕”×1
                   { ["class_id"] = 5034, ["amount"] = 1, ["ratio"] = 100, }, };                                    -- 宝物“秩序腰带”×1
    elseif grade == INSTANCE_GRADE_NORMAL then
        arr2   = { { ["class_id"] = 1102, ["amount"] = math.max(1, math.modf(layer / 20)), ["ratio"] = 100 },       -- 魔铁+floor/20
                   { ["class_id"] = 1104, ["amount"] = math.max(1, math.modf(layer / 20)), ["ratio"] = 100 }, };    -- 暗钢+floor/20
        arr    = { { ["class_id"] = 5021, ["amount"] = 1, ["ratio"] = 100, },                                       -- 宝物“十字军头盔”×1
                   { ["class_id"] = 5022, ["amount"] = 1, ["ratio"] = 100, },                                       -- 宝物“十字军铠甲”×1
                   { ["class_id"] = 5023, ["amount"] = 1, ["ratio"] = 100, },                                       -- 宝物“十字军手套”×1
                   { ["class_id"] = 5024, ["amount"] = 1, ["ratio"] = 100, }, };                                    -- 宝物“十字军绶带”×1
    else
        arr2   = { { ["class_id"] = 1102, ["amount"] = math.max(1, math.modf(layer / 20)), ["ratio"] = 100 }, };    -- 魔铁+floor/20
        arr    = { { ["class_id"] = 5011, ["amount"] = 1, ["ratio"] = 100, },                                       -- 宝物“骑士头盔”×1
                   { ["class_id"] = 5012, ["amount"] = 1, ["ratio"] = 100, },                                       -- 宝物“骑士锁甲”×1
                   { ["class_id"] = 5013, ["amount"] = 1, ["ratio"] = 100, },                                       -- 宝物“骑士手套”×1
                   { ["class_id"] = 5014, ["amount"] = 1, ["ratio"] = 100, }, };                                    -- 宝物“骑士绶带”×1
    end

    local ret = {};
    local bonus;

    if maxHp > 0 then
        -- 属性奖励
        table.insert(ret, { 2, "max_hp", maxHp, });
    end

    if #arr2 > 0 then
        -- 物品奖励
        bonus = fetchElemBySeed(arr2, randSeed);
        table.insert(ret, { 1, bonus["class_id"], bonus["amount"], });
    end

    if #arr > 0 then
        -- 物品奖励
        bonus = fetchElemBySeed(arr, randSeed2);
        table.insert(ret, { 1, bonus["class_id"], bonus["amount"], });
    end

    return ret;
end